package com.tianshuo.listener.service;

import com.tianshuo.listener.event.OrderEvent;
import com.tianshuo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @ClassName : OrderService
 * @Description : 测试Spring的发布订阅模式。
 * @Author : tianshuo
 * @Date: 2020-09-23 18:09
 */
@Component
public class OrderService {

    @Autowired
    private ApplicationContext applicationContext;

    public OrderService() {
    }

    public void publish() {
        User user = new User();
        user.setName("ddd");
        // 发布基于annotation的事件
        applicationContext.publishEvent(user);

        // 发布基于接口的是时间
        applicationContext.publishEvent(new OrderEvent(user));
    }
}

